package cn.itcast.hiss.process.activiti.handler.task;

import cn.hutool.core.util.StrUtil;
import cn.itcast.hiss.api.client.task.AddExecutionTask;
import cn.itcast.hiss.cmd.handler.CmdHandler;
import cn.itcast.hiss.handler.HandlerIdClientEnum;
import cn.itcast.hiss.message.Message;
import cn.itcast.hiss.message.MessageContext;
import cn.itcast.hiss.message.sender.task.AddExecutionTaskMessage;
import cn.itcast.hiss.process.activiti.service.ActivitiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Task_BeforeSignTaskHandler implements CmdHandler<AddExecutionTaskMessage> {

    @Autowired
    private ActivitiService activitiService;

    @Override
    public void invoke(Message params, MessageContext messageContext) {
        AddExecutionTask palyload = (AddExecutionTask) params.getPalyload();
        if (StrUtil.isEmpty(palyload.getOperatorName())) {
            palyload.setOperatorName("前加签");
        }
        activitiService.beforeSignTask((AddExecutionTaskMessage) params, messageContext);
    }

    @Override
    public String getId() {
        return HandlerIdClientEnum.TASK_BEFORE_SIGN_TASK.getId();
    }
}
